package schedule.model;

import java.util.ArrayList;

public class Advisor {

	public int id;
	public ArrayList<InputTime> availableTimes;
	public MilTimeSchedule monMil;
	public MilTimeSchedule tueMil;
	public MilTimeSchedule wedMil;
	public MilTimeSchedule thuMil;
	public MilTimeSchedule friMil;
	public String firstName, lastName, email;

	public Advisor(int id) {
		this.id = id;
		availableTimes = new ArrayList<InputTime>();
		initialize();
	}

	public Advisor(int id, String firstName, String lastName) {
		super();
		this.id = id;
		this.firstName = firstName;
		this.lastName = lastName;
		availableTimes = new ArrayList<InputTime>();
		initialize();
	}

	public void initialize() {
		monMil = new MilTimeSchedule();
		tueMil = new MilTimeSchedule();
		wedMil = new MilTimeSchedule();
		thuMil = new MilTimeSchedule();
		friMil = new MilTimeSchedule();

	}

	public void addTime(InputTime newTime) {
		availableTimes.add(newTime);
	}

	public void createSchedules() {
		createMyMilTime();
	}

	private void createMyMilTime() {
		// appends hr and min together, as milTimeSchedule expects. i.e. sHr= 10
		// sMin= 45 turns into 1045
		for (InputTime a : availableTimes) {
			StringBuffer sBuffer = new StringBuffer();
			sBuffer.append(a.startHr);
			sBuffer.append(a.startMn);
			int startTime = Integer.parseInt(sBuffer.toString());
			if (a.startMn == 0)
				startTime = startTime * 10;
			sBuffer.delete(0, sBuffer.length());
			sBuffer.append(a.endHr);
			sBuffer.append(a.endMn);
			int endTime = Integer.parseInt(sBuffer.toString());
			if (a.endMn == 0)
				endTime = endTime * 10;
			int dayNum = a.currentDay;
			switch (dayNum) {
			case 0:
				monMil.setAvailable(startTime, endTime);
				break;
			case 1:
				tueMil.setAvailable(startTime, endTime);
				break;
			case 2:
				wedMil.setAvailable(startTime, endTime);
				break;
			case 3:
				thuMil.setAvailable(startTime, endTime);
				break;
			case 4:
				friMil.setAvailable(startTime, endTime);
				break;
			}
		}
	}
}
